package org.example.news_check.Controller;

import org.example.news_check.Pojo.Communicate;
import org.example.news_check.Pojo.Result;
import org.example.news_check.Service.CommunicateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/communicate") // 控制器统一前缀 /communicate
public class CommunicateController {

    @Autowired
    private CommunicateService communicateService;

    @GetMapping("/listTree") // 更明确地指定 GET 方法
    public Result listTree() {
        List<Communicate> list = communicateService.listTree();
        return Result.success(list);
    }

    @PostMapping("/save") // 更明确地指定 POST 方法
    public Result save(@RequestBody Communicate communicate) {
        communicate.setCreateTime(java.time.LocalDateTime.now());
        communicateService.save(communicate);
        return Result.success();
    }


    @GetMapping("/listTreeByArticleId/{articleId}")
    public Result listTreeByArticleId(@PathVariable("articleId") Integer articleId) {
        List<Communicate> list = communicateService.listTreeByArticleId(articleId);
        return Result.success(list);
    }
}
